<?php
require_once '../model/db.php';
$db= new DB();
$username = "root";
$password = "vertrigo";
$host = "localhost";
$database = "web2";


$link = mysql_connect($host, $username, $password);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

// Select your database
mysql_select_db($database);

if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {

    // Temporary file name stored on the server
    $tmpName = $_FILES['image']['tmp_name'];

    // Read the file 
    $fp = fopen($tmpName, 'r');
    $data = fread($fp, filesize($tmpName));
    $data = addslashes($data);
    fclose($fp);


    // Create the query and insert
    // into our database.
    $query = "INSERT INTO tbl_images ";
    $query .= "(image) VALUES ('$data')";
    $results = mysql_query($query, $link) or die(mysql_error());

    // Print results
    print "Thank you, your file has been uploaded.";
} else {
    print "No image selected/uploaded";
}
?>
